

public class HarvestNode {
	
	int type;
	Tile node;
	int workers;
	HarvestNode next;
	HarvestNode previous;
	final int FOOD =1,	METAL = 2, POWER = 3;
	
	public HarvestNode(Tile temp, int _type){
		node = temp;
		next = null;
		previous = null;
		type = _type;
		workers=0;
	}
	
	
	// ========== GETTERS ============
	public int type(){return this.type;}
	public HarvestNode next(){return next;}
	public Tile node(){return node;}
	public boolean hasNext(){ return (next==null) ? false : true;}
	public String toString(){return node.toString()+ " Workers: "+workers;}
	public boolean equals(Tile tile){ return (tile.x == node.x && tile.y == node.y)? true : false;}
	
	
	
	
	// ========== SETTERS ============
	public void next(HarvestNode temp){next = temp;}
	public void previous(HarvestNode temp){previous = temp;}
	public void end(){previous.next(null);}
	
	public void die(){remove();}
	public int remove(){
		node.unassign();
		int x = workers;
		workers = 0;
		
		if(previous == null && next == null) return x;
		
		if(previous != null) 
			previous.next(next) ;
		if(next == null)
			previous.end();
		
		return x;
	}
	
	
	// ========== DO STUFF ===========
	public int harvest(){return node.harvest(type, workers * 10);}
	public void assign(int x){this.workers += x;}
	
	public int unassign(int x)
	{
		int y=0;
		
		if(workers < x){
			y = workers;
			workers = 0;
		}else{
			y = workers - x;
			workers =- x;
		}
		
		return y;
	}
	
}